package com.es.order.listener;

import com.es.order.entity.OrderDO;
import com.es.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 描述:
 * Old-AgeCareSystem-
 *
 * @author Derek
 * @create 2021-12-09 12:21
 */
@Component
@Slf4j
public class OrderCloseListener {

    @Autowired
    private OrderService service;

    @RabbitListener(queues = "order-queue-dlx")
    public void changeOrderStatus(String  msg, Message message){
        try {
            log.info("要处理的订单号是:{}", msg);
            OrderDO orderDO = service.getById(Long.valueOf(msg));
            if(orderDO.getOrderStatus() ==  2){
                orderDO.setOrderStatus(0);
                service.updateById(orderDO);
            }
            log.info("订单更新成功");
        }catch (Exception e){
            log.error(e.getMessage());

        }
    }
}
